package myTest.chat.client;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class Client {
	private static final String path = "/home/chenwei/Documents/";

	public static void main(String[] args) throws Exception {
		File file = new File(path + "pic.jpg");

		Socket s = new Socket("192.168.1.102", 10005);

		BufferedInputStream fileReader = new BufferedInputStream(new FileInputStream(file));// read binary

		BufferedOutputStream socOut = new BufferedOutputStream(s.getOutputStream());// write binary PrintWriter auto
																					// flush

		BufferedReader socIn = new BufferedReader(new InputStreamReader(s.getInputStream()));// read string

		for (int data; (data = fileReader.read()) != -1;)
			socOut.write(data);
		socOut.flush();// this is very important sentence without witch you
						// would lose data.
		s.shutdownOutput();// 给流加上一个结束标识，让对方的读取流可以结束。

		String str = socIn.readLine();// read string "success"
		System.out.println(str);

		fileReader.close();
		s.close();
	}
}
